package me.dev.demo;

import com.jfinal.aop.Before;
import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;
import com.jfinal.i18n.I18n;
import com.jfinal.i18n.Res;
import me.dev.core.DateUtils;

/******************************************************************************
 * 北京易华录信息技术股份有限公司
 * ----------------------------------------------------------------------------
 * 模块名称:模块名称
 * 类 名 称:me.dev.demo.HelloController
 * 版　　本:Version 1.0
 * <p/>
 * 作 成 日:12/3/2015   Version 1.0   作　成　者:Liuwx
 * 最终更新:12/3/2015   Version 1.0   最终更新者:Liuwx
 * ----------------------------------------------------------------------------
 * 更新履历:
 * 12/3/2015   Version.1.0   初版作成者:Liuwx
 ******************************************************************************/

public class HelloController extends Controller {

    @Before({DemoInterceptor.class})
    public void index() {
//        Record user = new Record();
//        user.set("user_name", "admin").set("password", "admin");
        Res resEn = I18n.use("zh_CN");
//        System.out.println(getPara());
        String msg = resEn.format("test.msg", DateUtils.now("yyyy-MM-dd HH:mm:ss"));
        System.out.println(">>>" + msg);
        renderText(msg);
    }

    @Before({AddUserValidator.class})
    @ActionKey("/user/add")
    public void addUser() {
        User user = new User();
        String userName = getPara(0);
        String password = getPara(1);
        user.set("userName", userName).set("password", password).save();
        renderText("添加用户'" + userName + "'成功！");
    }

    @ActionKey("/user/find")
    public void findUser() {
        int id = getParaToInt(0);
        User user = User.dao.findById(id);
        if (user != null) {
            renderText("找到编号为'" + id + "'用户名为：" + user.getStr("userName"));
        } else {
            renderText("未找到id为'" + id + "'的用户！");
        }
    }
}
